import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'time_manager.settings')
django.setup()

from users.models import User


def test_user():
    # 创建用户
    user = User.objects.create(
        username = 'testuser',
        phone = '13800138000'
    )
    user.set_password('test123')
    user.save()
    print(f"✅ 创建用户成功: {user.username} (ID: {user.id})")

    # 查询用户
    queried_user = User.objects.get(phone = '13800138000')
    print(f"✅ 查询用户成功: {queried_user.username}")
    print(f"    创建时间: {queried_user.created_at}")

    # 验证密码
    print("✅ 测试完成")


if __name__ == '__main__':
    test_user()